package com.dsj.gxrd.modules.controller.activity;

import com.dsj.gxrd.modules.activity.domain.dto.RdNewsApprovalDto;
import com.dsj.gxrd.modules.activity.domain.dto.RdNewsDto;
import com.dsj.gxrd.modules.activity.domain.query.RdNewsQuery;
import com.dsj.gxrd.modules.activity.domain.vo.RdNewsVo;
import com.dsj.gxrd.modules.activity.service.RdNewsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.annotation.RequiresRoles;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author songpin566
 * @date 2023/09/14
 **/
@Api(tags = "文章新闻")
@RestController
@RequestMapping("/activity/news")
public class RdNewsController extends BaseController {

    @Autowired
    private RdNewsService rdNewsService;

    @RequiresPermissions("activity:news:list")
    @GetMapping("/list")
    public TableDataInfo list(RdNewsQuery rdNewsQuery) {
        startPage();
        List<RdNewsVo> list = rdNewsService.selectRdNewsList(rdNewsQuery);
        return getDataTable(list);
    }

    @RequiresPermissions("activity:news:add")
    @ApiOperation(value = "新增新闻信息")
    @PostMapping()
    public AjaxResult add(@RequestBody RdNewsDto rdNewsDto) {
        return toAjax(rdNewsService.insertRdNews(rdNewsDto));
    }

    @RequiresPermissions("activity:news:edit")
    @ApiOperation(value = "修改新闻信息")
    @PutMapping()
    public AjaxResult edit(@RequestBody RdNewsDto rdNewsDto) {
        return toAjax(rdNewsService.updateRdNews(rdNewsDto));
    }

    @RequiresPermissions("activity:news:query")
    @ApiOperation(value = "查询新闻信息详情")
    @GetMapping("/{rdNewsId}")
    public AjaxResult getInfo(@PathVariable Long rdNewsId) {
        RdNewsVo rdNewsVo=rdNewsService.getInfo(rdNewsId);
        return AjaxResult.success(rdNewsVo);
    }

    @RequiresPermissions("activity:news:approval")
    @ApiOperation(value = "审核新闻发布")
    @PostMapping("/approval")
    public AjaxResult approval(@RequestBody RdNewsApprovalDto approvalDto) {
        return rdNewsService.approval(approvalDto);
    }

    @RequiresPermissions("activity:news:del")
    @DeleteMapping("/{rdNewsIds}")
    public AjaxResult removes(@PathVariable List<Long> rdNewsIds) {
        return rdNewsService.removes(rdNewsIds);
    }

}
